Page({
  data: {
    part:['头部','五官','上肢','胸部','腹部','盆骨','臀部','下肢','皮肤','其他'],
    keyword:[],
    currentIndex:0,
    //切换部位后关键词重新置顶显示
    backTop: -1
  },

  onLoad: function (options) {
    this.getKeyword(this.data.part[this.data.currentIndex])
  },

  // 获取关键字
  getKeyword(part){
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    wx.cloud.callFunction({
      name:'getKeyword',
      data:{ part }
    }).then(res =>{
      this.setData({
        keyword:res.result.data
      })
      wx.hideLoading()
    }).catch(err => console.log('云函数调用失败',err))
  },

  // 点击部位
  handlePart(e){
    if(this.data.currentIndex === e.currentTarget.dataset.index){
      return
    }else{
      let {index} = e.currentTarget.dataset
      this.setData({
        currentIndex:index,
        backTop:0
      })
      const part = this.data.part[index]
      this.getKeyword(part)
    }

  },

  // 点击关键字
  handleKeyword(e){
    let {index} = e.currentTarget.dataset
    let keyword = this.data.keyword[index]
    const part = this.data.part[this.data.currentIndex]
    wx.navigateTo({
      url: '/pages/more_keyword/more_keyword?part='+part+'&keyword='+keyword,
    })
  }
})